import { Component, OnInit, SimpleChanges } from '@angular/core';
import { LimitedCompany } from "../farm-load-trend/limited-company";
import { TagData } from "../../../entity/tag-data.model";
import { Farm } from "../../../entity/farm.model";
import { LimitedFarmLoad } from "./limited-farm-load";
import { FarmService } from "../../../service/farm.service";
import { DatePipe } from "@angular/common";
import { DataSourceService } from "../../../service/data-source/data-source.service";
import { ApplicationService } from "../../../service/application.service";
import { Tag } from '../../../entity/tag.model';

@Component({
    selector: 'app-farm-load-trend',
    templateUrl: './farm-load-trend.component.html',
    styleUrls: ['./farm-load-trend.component.css'],
    providers: [DataSourceService]
})
export class FarmLoadTrendComponent implements OnInit {

    public titleCompany: string;
    private historyInterval: number = 1 * 600;    //600秒
    private pushInterval: number = /* 10 * 60 */900;      //900秒
    private now: Date = new Date();
    private startTime: Date = new Date(this.now.getFullYear(), this.now.getMonth(), this.now.getDate());
    private endTime: Date = new Date();

    public isCheckedMeanWindSpeed: boolean = true;
    public isCheckedPower: boolean = true;
    public isCheckedAgc: boolean = true;
    public isCheckedYestdayWindSpeed: boolean = true;
    public isCheckedYestdayPower: boolean = true;
    public isCheckedGriFPowers: boolean = true;
    /**
   * echarts实例对象
   * 
   * @private
   * @type {*}@memberof RealtimePowerPanelComponent
   */
    private echartsIntance: any;
    private option: object;

    /**
   * 实时数据点集合
   * 
   * @private
   * @type {TagValue[]}
   * @memberof TurbineListComponent
   */
    private tagDatas: TagData[] = [];

    /**
     * 风场负荷模型
     * 
     * @type {LimitedFarm[]}
     * @memberof FarmEchartsComponent
     */
    public limitedFarmsLoads: LimitedFarmLoad[] = [];

    /**
     * 风场集合 
     * 
     * @type {Farm[]}
     * @memberof FarmEchartsComponent
     */
    public farms: Farm[] = [];

    /**
     * 公司风速
     * 
     * @type {Farm[]}
     * @memberof FarmEchartsComponent
     */
    public companyMeanWindSpeed: number = 0;

    /**
    * 公司功率 
    * 
    * @type {Farm[]}
    * @memberof FarmEchartsComponent
    */
    public companyPower: number = 0;

    /**
     * 公司AGC值 
     * 
     * @type {Farm[]}
     * @memberof FarmEchartsComponent
     */
    public companyAGCFeedBackValue: number;

    /**
     * 公司风速集合
     * 
     * @type {Farm[]}
     * @memberof FarmEchartsComponent
     */
    public companyMeanWindSpeedDates: any[] = [];

    /**
    * 公司功率集合
    * 
    * @type {Farm[]}
    * @memberof FarmEchartsComponent
    */
    public companyPowerDates: any[] = [];

    /**
     * 公司AGC值集合
     * 
     * @type {Farm[]}
     * @memberof FarmEchartsComponent
     */
    public companyAGCFeedBackValueDates: any[] = [];

    /**
     * 公司昨日风速、昨日功率数据集合(折线图集合)
     * 
     * @type {Farm[]}
     * @memberof FarmEchartsComponent
     */
    public compYestdayWindSpeeds: any[] = [];
    public compYestdayPowers: any[] = [];

    /**
     * 公司预测功率集合
     * 
     * @type {Farm[]}
     * @memberof FarmEchartsComponent
     */
    public companyGriFPowers: any[] = [];

    public options: object;
    /**
   *是否加载限电量
   *
   * @memberof FarmEchartsComponent
   */
    isShowLimitedPower = false;
    constructor(
        private farmService: FarmService,
        private dataSource: DataSourceService,
        private application: ApplicationService,
        private datePipe: DatePipe,
    ) {
        this.titleCompany = this.application.currentCompany.companyName;
    }

    public ngOnInit() {
        this.isShowLimitedPower = this.application.currentCompany.isLimited;
        this.initData();
        this.initOption();
    }

    public ngOnDestroy(): void {
        this.dataSource.dispose();
    }

    private initData() {
        this.farmService.getFarms()
            .then(res => {
                this.farms = res
                this.createLimitedFarm(res);
            })
            .catch(error => {
                //报错日志；
                console.log('app-farm-echarts', error);
            })
    }

    private createLimitedFarm(farms: Farm[]) {
        let WindSpeed = this.application.tagDict["MeanWindSpeed"];              //平均风速
        let Power = this.application.tagDict["Power"];                          //有功功率
        let AGCFeedBackValue: Tag;    //AGC
        let GriFPower = this.application.tagDict["GriFPower"];                  //预测功率
        if (this.isShowLimitedPower) {
            AGCFeedBackValue = this.application.tagDict["AGCFeedBackValue"];
        }
        // this.dataSource.binding([farms[0].farmCode], WindSpeed),
        farms.forEach((farm) => {
            //创建数据模型
            let limitedFarmLoad: LimitedFarmLoad = {
                farmId: farm.farmId,
                farmCode: farm.farmCode,
                farmName: farm.farmName,

                meanWindSpeedBinging: this.dataSource.binding([farm.farmCode], WindSpeed),
                meanWindSpeeds: [],
                meanWindSpeed: null,

                powerBinging: this.dataSource.binding([farm.farmCode], Power),
                powers: null,
                power: null,


                griFPowerCode: this.dataSource.buildTagCode([farm.farmCode.replace('_1', '_3')], GriFPower),
                griFPowers: null,

                yesterdayWindSpeeds: [],
                yesterdayPowers: [],
                time: new Date()
            }
            if (AGCFeedBackValue) {
                limitedFarmLoad.AGCFeedBackValueBinging = this.dataSource.binding([farm.farmCode], AGCFeedBackValue);
                limitedFarmLoad.AGCFeedBackValues = [];
                limitedFarmLoad.AGCFeedBackValue = null;
            }
            this.limitedFarmsLoads.push(limitedFarmLoad);   //初始化数据

        });

        //绑定数据
        this.dataSource
            .withHistories(this.startTime, this.endTime, { history: this.historyInterval, push: this.pushInterval })
            .subscribe(
                next => {    
                    let cWindSpeed: number = 0;
                    let cPower: number = 0;
                    let cAGCFeedBackValue: number = 0;
                    if (next.intervalData) {  //返回当前的数据
                        let cTime = next.time;  //返回数据的时间（当前）
                        this.limitedFarmsLoads.forEach(farm => {
                            if (this.isShowLimitedPower) {
                                let agc = farm.AGCFeedBackValueBinging;
                                farm.AGCFeedBackValue = [agc.time, agc.value.toFixed(2)];
                                cAGCFeedBackValue += Number(agc.value);
                            }

                            let wind = farm.meanWindSpeedBinging;
                            let power = farm.powerBinging;


                            farm.meanWindSpeed = [wind.time, wind.value.toFixed(2)];
                            farm.power = [power.time, power.value.toFixed(2)];

                            cWindSpeed += Number(wind.value);
                            cPower += Number(power.value);             
                        });
                        //显示当前数据
                        this.companyMeanWindSpeed = cWindSpeed / this.limitedFarmsLoads.length;
                        this.companyPower = cPower;
                        if (this.isShowLimitedPower) {
                            this.companyAGCFeedBackValue = cAGCFeedBackValue;
                            this.companyAGCFeedBackValueDates.push([cTime, cAGCFeedBackValue.toFixed(2)]);

                        }


                        //图表数据更新
                        this.companyMeanWindSpeedDates.push([cTime, (cWindSpeed / this.limitedFarmsLoads.length).toFixed(2)]);
                        this.companyPowerDates.push([cTime, cPower.toFixed(2)]);
                        this.updateEchart();
                    }
                    if (next.historyData) {     //返回历史数据
                        this.limitedFarmsLoads.forEach(farm => {
                            let wsHistoryData = next.historyData.filter(o => o.code == farm.meanWindSpeedBinging.code);
                            let wsHistoryTrend: any[] = [];
                            wsHistoryData.forEach(tagData => {
                                try {
                                    wsHistoryTrend.push([tagData.time, tagData.value.toFixed(2)]);
                                }
                                catch (error) {
                                    console.log(error);
                                }
                            });
                            farm.meanWindSpeeds = wsHistoryTrend;
                            let powerHistoryData = next.historyData.filter(o => o.code == farm.powerBinging.code);
                            let powerHistoryTrend: any[] = [];
                            powerHistoryData.forEach(tagData => {
                                try {
                                    powerHistoryTrend.push([tagData.time, tagData.value.toFixed(2)]);
                                }
                                catch (error) {
                                    console.log(error);
                                }
                            });
                            farm.powers = powerHistoryTrend;
                            if (this.isShowLimitedPower) {
                                let agcHistoryData = next.historyData.filter(o => o.code == farm.AGCFeedBackValueBinging.code);
                                let agcHistoryTrend: any[] = [];
                                agcHistoryData.forEach(tagData => {
                                    try {
                                        agcHistoryTrend.push([tagData.time, tagData.value.toFixed(2)]);
                                    }
                                    catch (error) {
                                        console.log(error);
                                    }
                                });
                                farm.AGCFeedBackValues = agcHistoryTrend;
                                cAGCFeedBackValue += agcHistoryTrend.length ? Number(agcHistoryTrend[agcHistoryTrend.length - 1][1]) : 0;
                            }
                            cWindSpeed += wsHistoryTrend.length ? Number(wsHistoryTrend[wsHistoryTrend.length - 1][1]) : 0;
                            cPower += powerHistoryTrend.length ? Number(powerHistoryTrend[powerHistoryTrend.length - 1][1]) : 0;

                        });
                        
                        //显示当前数据
                        this.companyMeanWindSpeed = cWindSpeed / this.limitedFarmsLoads.length;
                        this.companyPower = cPower;
                        if (this.isShowLimitedPower) {
                            this.companyAGCFeedBackValue = cAGCFeedBackValue;
                        }

                        //公司历史数据图表加载，根据时间过滤所有的数据，找到当前时间点的数据集合；
                        let windSpeedDates: any[] = [];
                        let powersDates: any[] = [];
                        let agcDates: any[] = [];
                        this.limitedFarmsLoads.map(o => windSpeedDates = windSpeedDates.concat(o.meanWindSpeeds));
                        this.limitedFarmsLoads.map(o => powersDates = powersDates.concat(o.powers));
                        if (this.isShowLimitedPower) {
                            this.limitedFarmsLoads.map(o => agcDates = agcDates.concat(o.AGCFeedBackValues));
                        };
                        for (let time = this.startTime; time < this.endTime; time = new Date(time.getTime() + this.historyInterval * 1000)) {
                            //公司风速平均值；
                            let total: number = 0;
                            let windspeeds = windSpeedDates.filter(o => new Date(o[0]).getTime() === time.getTime());

                            // let windspeeds = windSpeedDates.filter(o => new Date(new Date(o[0]).getFullYear(),new Date(o[0]).getMonth(),new Date(o[0]).getDate(),new Date(o[0]).getHours(),new Date(o[0]).getMinutes()).getTime() === time.getTime());
                            windspeeds.map(o => total += Number(o[1]) * 1);
                            let companyMeanWindSpeed = total / this.limitedFarmsLoads.length;
                            this.companyMeanWindSpeedDates.push([time, companyMeanWindSpeed.toFixed(2)]);

                            //公司功率合计；
                            let totalPower: number = 0;
                            let talPowers = powersDates.filter(o => new Date(o[0]).getTime() === time.getTime());
                            talPowers.map(o => totalPower += o[1] * 1)
                            this.companyPowerDates.push([time, totalPower.toFixed(2)]);
                            if (this.isShowLimitedPower) {
                                //公司AGC值合计
                                let totalAGC: number = 0;
                                let talAGCvalues = agcDates.filter(o => new Date(o[0]).getTime() === time.getTime());
                                talAGCvalues.map(o => totalAGC += o[1] * 1)
                                this.companyAGCFeedBackValueDates.push([time, totalAGC.toFixed(2)]);
                            }


                        }

                        this.updateEchart();
                      
                    }
                    console.log(this.limitedFarmsLoads)
                },
                error => {
                    console.log("FarmLoadTrend subDataStream error", error);
                }
            );


        //加载昨日风速和功率
        let yesterdayCodes: string[] = [];
        yesterdayCodes.push(...this.limitedFarmsLoads.map(o => o.meanWindSpeedBinging.code));
        yesterdayCodes.push(...this.limitedFarmsLoads.map(o => o.powerBinging.code));

        let startTime: Date = new Date(this.now.getFullYear(), this.now.getMonth(), this.now.getDate() - 1);    //前一天0点
        let endTime: Date = new Date(this.now.getFullYear(), this.now.getMonth(), this.now.getDate());         //今天0点

        this.dataSource.history
            .getHistories(yesterdayCodes, startTime, endTime, this.historyInterval)
            .then(res => {
                if (res.length && res.length > 0)
                    this.getYesterday(res, startTime, endTime);
            })
            .catch(error => {
                console.log(error);
            });

        //加载预测功率
        let griFPowerStrarTime: Date = new Date(this.now.getFullYear(), this.now.getMonth(), this.now.getDate());
        let griFPowerEndTime = new Date(this.now.getFullYear(), this.now.getMonth(), this.now.getDate() + 1);
        let griFPowersCode: string[] = [];
        griFPowersCode.push(...this.limitedFarmsLoads.map(o => o.griFPowerCode));
        this.dataSource.history
            .getHistories(griFPowersCode, griFPowerStrarTime, griFPowerEndTime, this.pushInterval)
            .then(
                next => {
                   
                    if (next.length && next.length > 0)
                        this.getGriFPower(next, griFPowerStrarTime, griFPowerEndTime);
                },
                error => {
                    console.log(error);
                }
            );
    }

    private parserDate(date) {    //转化为标准日期格式；
        let t = Date.parse(date);
        if (!isNaN(t)) {
            return new Date(Date.parse(date.replace(/-/g, "/")));
        } else {
            return new Date();
        }
    };

    private getYesterday(res: TagData[], startTime: Date, endTime: Date) {
        this.limitedFarmsLoads.forEach(farm => {
            let yesterdayWindSpeeds: any[] = [];
            let yesterdayPowers: any[] = [];

            let farmYesterdayWindSpeeds = res.filter(o => o.code === farm.meanWindSpeedBinging.code);
            let farmYesterdayPowers = res.filter(o => o.code === farm.powerBinging.code);

            if (farmYesterdayWindSpeeds && farmYesterdayWindSpeeds.length) {
                farmYesterdayWindSpeeds.forEach(yestWindSpeed => {
                    let time: Date = this.parserDate(yestWindSpeed.time)
                    yesterdayWindSpeeds.push([time, yestWindSpeed.value.toFixed(2)])
                });
                farm.yesterdayWindSpeeds = yesterdayWindSpeeds;
            };

            if (farmYesterdayPowers && farmYesterdayPowers.length) {
                farmYesterdayPowers.forEach(yestPowers => {
                    let time: Date = this.parserDate(yestPowers.time)
                    yesterdayPowers.push([time, yestPowers.value.toFixed(2)])
                });
                farm.yesterdayPowers = yesterdayPowers;
            };
        });
        let yesterdayWindSpeedDatas: any[] = [];
        let yesterdayPowerDatas: any[] = [];
        this.limitedFarmsLoads.map(o => yesterdayWindSpeedDatas = yesterdayWindSpeedDatas.concat(o.yesterdayWindSpeeds));
        this.limitedFarmsLoads.map(o => yesterdayPowerDatas = yesterdayPowerDatas.concat(o.yesterdayPowers));

        for (let time = startTime; time < endTime; time = new Date(time.getTime() + this.historyInterval * 1000)) {
            //公司昨日风速平均值；
            let total: number = 0;
            let windspeeds = yesterdayWindSpeedDatas.filter(o => o[0].getTime() === time.getTime());
            windspeeds.map(o => total += Number(o[1]) * 1);
            let companyMeanWindSpeed = total / this.limitedFarmsLoads.length;
            this.compYestdayWindSpeeds.push([time, companyMeanWindSpeed.toFixed(2)]);

            //公司昨日功率合计；
            let totalPower: number = 0;
            let talPowers = yesterdayPowerDatas.filter(o => o[0].getTime() === time.getTime());
            talPowers.map(o => totalPower += Number(o[1]) * 1);
            this.compYestdayPowers.push([time, totalPower.toFixed(2)]);
        }
        this.updateEchart();
    }

    private getGriFPower(res: TagData[], startTime: Date, endTime: Date) {
        //this.companyGriFPowers = [];
        this.limitedFarmsLoads.forEach(farm => {
            let griFPowers: any[] = [];
            let farmGriFPowers = res.filter(o => o.code === farm.griFPowerCode);
            if (farmGriFPowers && farmGriFPowers.length) {
                farmGriFPowers.forEach(grifpower => {
                    griFPowers.push([grifpower.time, grifpower.value.toFixed(2)])
                });
                farm.griFPowers = griFPowers;
            }
        });

        let compGrifPowers: any[] = [];
        this.limitedFarmsLoads
            .filter(o => o.griFPowers !== null && o.griFPowers.length > 0)
            .map(o => compGrifPowers = compGrifPowers.concat(o.griFPowers));
        let index = 0;
        let point: any[] = null;
        for (let time = startTime; time < endTime; time = new Date(time.getTime() + this.historyInterval * 1000)) {
            // 预测功率；
            let totalPower = 0;
            const talPowers = compGrifPowers.filter(o => this.parserDate(o[0]).getTime() === time.getTime());
            talPowers.map(o => totalPower += o[1] * 1);
            // 数据返回的时间间隔和this.historyInterval不一致，以下代码避免出现波浪线
            if (talPowers.length === 0 && point != null) {
                totalPower = Number(point[1]);
            }
            point = [time, totalPower.toFixed(2)];
            this.companyGriFPowers.push(point);
            index++;
        }
        this.updateEchart();
    }

    public windSpeedChecked(check: boolean) {
        this.isCheckedMeanWindSpeed = check;
        this.selected['今日风速(m/s)'] = check;
        this.updateLenged()
    }

    public powerChecked(check: boolean) {
        this.isCheckedPower = check;
        this.selected['今日功率(MW)'] = check;
        this.updateLenged();
    }

    public agcChecked(check: boolean) {
        this.isCheckedAgc = check;
        this.selected['当前AGC值(MW)'] = check;
        this.updateLenged();
    }

    public yestdayPowersChecked(check: boolean) {
        this.isCheckedYestdayPower = check;
        this.selected['昨日有功功率(MW)'] = check;
        this.updateLenged();
    }

    public yestdayWindSpeedChecked(check: boolean) {
        this.isCheckedYestdayWindSpeed = check;
        this.selected['昨日风速(m/s)'] = check;
        this.updateLenged();
    }

    public griFPowersChecked(check: boolean) {
        this.isCheckedGriFPowers = check;
        this.selected['预测功率(MW)'] = check;
        this.updateLenged();
    }

    private selected = {
        '今日风速(m/s)': this.isCheckedMeanWindSpeed,
        '今日功率(MW)': this.isCheckedPower,
        '当前AGC值(MW)': this.isCheckedAgc,
        '昨日有功功率(MW)': this.isCheckedYestdayPower,
        '昨日风速(m/s)': this.isCheckedYestdayWindSpeed,
        '预测功率(MW)': this.isCheckedGriFPowers
    };

    private legend: any = {
        icon: 'rect',
        itemWidth: 14,
        itemHeight: 5,
        itemGap: 3,
        top: 20,
        // data: ['当前风速', '当前功率', '当前AGC值', '昨日有功功率', '昨日风速','预测功率(MW)'],  //, '投退状态'
        right: '10%',
        textStyle: {
            fontSize: 12,
            color: '#F1F1F3'
        },
        selected: this.selected
    }

    private series: any = [
        {
            name: '今日风速(m/s)',
            type: 'line',
            smooth: true,
            symbol: 'circle',
            symbolSize: 5,
            yAxisIndex: 1,
            showSymbol: false,
            lineStyle: {
                normal: {
                    width: 1
                }
            },
            itemStyle: {
                normal: {
                    color: '#FFFF00',
                    borderColor: 'rgba(137,189,2,0.27)',
                    borderWidth: 12,
                    lineStyle: {
                        color: '#FFFF00'
                    }

                }
            },
            data: this.companyMeanWindSpeedDates
        },
        {
            name: '今日功率(MW)',
            type: 'line',
            smooth: true,
            symbol: 'circle',
            symbolSize: 5,
            showSymbol: false,
            lineStyle: {
                normal: {
                    width: 1
                }
            },

            itemStyle: {
                normal: {
                    color: '#1E90FF',
                    borderColor: 'rgba(0,136,212,0.2)',
                    borderWidth: 12,
                    lineStyle: {
                        color: '#1E90FF'
                    }
                }
            },
            data: this.companyPowerDates

        },
        {
            name: '当前AGC值(MW)',
            type: 'line',
            smooth: true,
            symbol: 'circle',
            symbolSize: 5,
            showSymbol: false,
            lineStyle: {
                normal: {
                    width: 1
                }
            },
            itemStyle: {
                normal: {
                    color: '#008000',
                    borderColor: 'rgba(0,136,212,0.2)',
                    borderWidth: 12,
                    lineStyle: {
                        color: '#008000'
                    }
                }
            },
            data: this.companyAGCFeedBackValueDates

        },
        {
            name: '昨日有功功率(MW)',
            type: 'line',
            smooth: true,
            symbol: 'circle',
            symbolSize: 5,
            showSymbol: false,
            xAxisIndex: 1,
            lineStyle: {
                normal: {
                    width: 1
                }
            },
            itemStyle: {
                normal: {
                    color: '#9370DB',
                    borderColor: 'rgba(0,136,212,0.2)',
                    borderWidth: 12,
                    lineStyle: {
                        color: '#9370DB'
                    }
                }
            },
            data: this.compYestdayPowers
        },
        {
            name: '昨日风速(m/s)',
            type: 'line',
            smooth: true,
            symbol: 'circle',
            symbolSize: 5,
            showSymbol: false,
            xAxisIndex: 1,
            yAxisIndex: 1,
            lineStyle: {
                normal: {
                    width: 1
                }
            },
            itemStyle: {
                normal: {
                    color: '#FF1493',
                    borderColor: 'rgba(0,136,212,0.2)',
                    borderWidth: 12,
                    lineStyle: {
                        color: '#FF1493'
                    }
                }
            },
            data: this.compYestdayWindSpeeds
        },
        {
            name: '预测功率(MW)',
            type: 'line',
            smooth: true,
            symbol: 'circle',
            symbolSize: 5,
            showSymbol: false,
            lineStyle: {
                normal: {
                    width: 1
                }
            },
            itemStyle: {
                normal: {
                    color: '#FF4500',
                    borderColor: 'rgba(0,136,212,0.2)',
                    borderWidth: 12,
                    lineStyle: {
                        color: '#FF4500'
                    }
                }
            },
            data: this.companyGriFPowers
        }
    ]

    private initOption() {
        let pipe = this.datePipe;
        let nowDate = new Date();
        this.options = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    lineStyle: {
                        color: '#57617B'
                    }
                },
                // formatter: function (params, ticket, callback) {
                //     let result = pipe.transform(new Date(params[0].data[0]), "HH:mm:ss") + "</br>";
                //     params.forEach((item) => {
                //         result += item.marker + item.seriesName + ":" + item.value[1] + "</br>";
                //     });
                //     return result;
                // }
            },
            legend: this.legend,
            grid: {
                left: '3%',
                right: '2%',
                bottom: '5%',
                top: '5%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'time',
                    min: new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate()),
                    max: new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate() + 1),
                    interval: 60000 * 60 * 2,
                    boundaryGap: false,
                    axisLine: {
                        lineStyle: {
                            color: '#35789d',
                            width: 2
                        }
                    },
                    axisLabel: {
                        // 该属性的用来定义坐标轴的标签;
                        formatter: function (value, index) {
                            return pipe.transform(new Date(value), "HH:mm");
                        },
                        rotate: 40,
                        margin: 10
                    },
                    splitLine: {
                        show: true,
                        lineStyle: {
                            color: '#1b4268'
                        }
                    },
                    axisTick: {
                        show: false
                    }
                },
                {
                    type: 'time',
                    min: new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate() - 1),
                    max: new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate()),
                    interval: 60000 * 60,
                    boundaryGap: false,
                    axisLine: {
                        lineStyle: {
                            color: '#35789d',
                            width: 2
                        }
                    },
                    show: false,
                    axisLabel: {
                        // 该属性的用来定义坐标轴的标签;
                        formatter: function (value, index) {
                            return pipe.transform(new Date(value), "HH:mm");
                        },
                        rotate: 40
                    },
                    splitLine: {
                        show: false,
                        lineStyle: {
                            color: '#57617B'
                        }
                    }
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    name: '功率：MW',
                    axisLabel: {
                        //也可以像X轴那样定义想要的显示效果
                        formatter: "{value}",
                        margin: 10
                    },
                    splitLine: {
                        show: true,
                        lineStyle: {
                            color: '#1b4268'
                        }
                    },
                    axisLine: {
                        lineStyle: {
                            color: '#35789d',
                            width: 2
                        }
                    },
                    axisTick: {
                        show: false
                    },
                },
                {
                    type: 'value',
                    name: '风速：m/s',
                    axisLabel: {
                        //也可以像X轴那样定义想要的显示效果
                        formatter: "{value}",
                        margin: 10
                    },
                    splitLine: {
                        show: true,
                        lineStyle: {
                            color: '#1b4268'
                        }
                    },
                    axisLine: {
                        lineStyle: {
                            color: '#35789d',
                            width: 2
                        }
                    },
                    axisTick: {
                        show: false
                    },
                },
            ],
            series: this.series
        };
    }

    //初始化图表数据
    public onChartInit(ec: any) {
        this.echartsIntance = ec;
        this.updateEchart();
    }

    //更新图表数据
    private updateEchart() {
        if (this.echartsIntance != null) {                  
            this.echartsIntance.setOption(this.options);          
        }
    }

    //复选框控制图例更新；
    private updateLenged() {
        if (this.echartsIntance != null) {
            this.echartsIntance.setOption({
                legend: {
                    selected: this.selected
                }
            });
        }

    }

}





// WEBPACK FOOTER //
// ./src/app/module/monitor/farm-load-trend/farm-load-trend.component.ts